// GEAR 2.5 - Game Engine Andy Reimann - Author: Andy Reimann <andy@moorlands-grove.de>
// (c) 2014 GEAR 2.5
#pragma once
#include "UberShader.h"
#include "FileResource.h"
#include "AbstractShaderPart.h"

#include <unordered_map>

namespace G2 
{

	enum ShaderBlockState {
		WAITING_FOR_SHADER_CODE = 1,
		READING_VERTEX_SHADER,
		READING_FRAGMENT_SHADER,
	};
	/** This class takes care of loading the content of an Shader block
	 * inside of an UberShader file.
	 * @created:	2014/02/09
	 * @author Andy Reimann <a.reimann@moorlands-grove.de>
	 */
	class ShaderBlockParser 
	{
		public:
			/** This constructs a new ShaderBlockParser.
			 */
			ShaderBlockParser(UberShader* uberShader, FileResource* file);
			void parse();
		protected:
		private:

			void parseLine(std::string const& line, std::stringstream& lineStr);

			void parseIncludeMacro(std::string const& line);


			void flushShaderPart(std::shared_ptr<AbstractShaderPart> newPart);
			
			
			std::shared_ptr<AbstractShaderPart> getInclude(std::string const& resource) const;



			static std::unordered_map<std::string,std::shared_ptr<AbstractShaderPart>> initDefaultIncludes();

			UberShader*		mUberShader;
			FileResource*	mFile;
			unsigned int	mCurrentState;
			std::shared_ptr<AbstractShaderPart>	mCurrentShaderPart;

			static std::unordered_map<std::string,std::shared_ptr<AbstractShaderPart>> gDefaultIncludes; // The registered default includes
	};
};